<div class="layui-form" lay-filter="layuiadmin-form-admin" style="padding: 20px 30px 0 0;">
    <script type="text/html" template>
        <div class="layui-form-item">
            <label class="layui-form-label">校区</label>
            <div class="layui-form-mid layui-form-text">{{ d.params.campus }}</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">课程</label>
            <div class="layui-input-inline layui-form-mid">{{ d.params.className }}</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">教师</label>
            <div class="layui-form-mid layui-form-text">{{ d.params.teacher }}</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">学分</label>
            <div class="layui-form-mid layui-form-text">{{ d.params.credit }}</div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">备注</label>
            <div class="layui-form-mid layui-form-text layui-input-inline">{{ d.params.remark }}</div>
        </div>
    </script>
    <div class="layui-form-item">
        <label class="layui-form-label">投币</label>
        <div class="layui-input-inline" style="width: 15%;">
            <input type="text" name="coin" placeholder="0" lay-verify="number|validCoinNum" class="layui-input">
        </div>
        <div class="layui-form-mid">
            / <span id="restCoin"></span>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">购书</label>
        <div class="layui-input-block">
            <input type="checkbox" name="buy" lay-skin="switch" lay-text="是|否">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">调剂</label>
        <div class="layui-input-block">
            <input type="checkbox" name="adjust" lay-skin="switch" lay-text="是|否">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">重修</label>
        <div class="layui-input-block">
            <input type="checkbox" name="retake" lay-skin="switch" lay-text="是|否">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <input type="button" lay-submit lay-filter="LAY-user-back-submit" value="确认" class="layui-btn">
    </div>
</div>

<script>
    layui.use(['admin', 'form'], function(){
        var form = layui.form, $ = layui.$;
        form.verify({
           validCoinNum: function (value, item) {
               debugger;
               var rest = $('#restCoin')[0].textContent;
               rest = parseInt(rest);
               if (value > rest) return "投币超出余额";
           }
        });
        form.render();
        $.ajax({
            url: "/uclass/elective/coininfo",
            dataType: 'json',
            complete: function (result) {
                result = result.responseJSON;
                var restCoin = result.data.rest;
                var rest = parseInt(restCoin);
                $('#restCoin').append(rest);
            }
        })
    });
</script>